package com.huanxing.cloud.common.security.hander;

import cn.hutool.core.collection.CollUtil;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.Authentication;

/** @description 认证成功事件处理器 @Author lijx @Date 2022/1/27 9:40 */
public abstract class AbstractAuthenticationSuccessEventHandler
    implements ApplicationListener<AuthenticationSuccessEvent> {
  @Override
  public void onApplicationEvent(AuthenticationSuccessEvent event) {
    Authentication authentication = (Authentication) event.getSource();
    if (CollUtil.isNotEmpty(authentication.getAuthorities())) {
      handle(authentication);
    }
  }

  /** 处理登录成功方法 */
  public abstract void handle(Authentication authentication);
}
